<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
class Forum extends Controller
{
    public function index()
    {
       return $this->fetch('pages/forum/forum');//view下的文件夹
    }
    public function editor(){
        return $this->fetch('pages/forum/editor');
    }
    public function submitArticle(){
        $request = Request::instance();  //接收数据
        $msg = $request->param();        //输出参数
        //照片处理，路径赋值
        $result = $this->toInsertArticle($msg);  //入库
        if($result){
            $req = array(
                'result' => 1
            );
            $ut = new Utiltool($req);
        }else{
            $ut = new Utiltool();
        }
    	return $ut->getdata();
    }
    public function toInsertArticle($msg){
        $data = [   
            'article_author' => $msg['author'],
            'article_category' => $msg['type'],
            'article_time' => date("Y-m-d h:i:s"),
            'article_content' => $msg['content'],
            'article_title' => $msg['title'],
            'article_picture' => $msg['picture'],
            'article_status' => 1
        ];
        try{
            $result = Db::table('Article_info')->insert($data);
        }catch(Exception $e){
            return $result;
        }
        return $result;
    }
}